package com.playball.lottery.frm.buyhall;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
//import com.playball.lottery.customview.ApplicationBall;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.JddMainActivity;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.MyDialog;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.kjinfo.KjinfoListByType;
import com.playball.lottery.frm.yhzx.BetRecordActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.frm.yhzx.ZhRecordActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.DynArrayInt;
import com.playball.lottery.util.Kuai3Util;
import com.playball.lottery.util.SensorListener;
import com.playball.lottery.util.SoundManage;
import com.playball.lottery.util.SysApplication;


/**
 * 快三选号界面
 * 
 * @author Administrator
 * 
 */
public class Kuai3Activity extends BaseActivity implements Serializable, DefConstants {
	/** 上下文内容 */
	private Context context = null;
	private static final long serialVersionUID = 1L;
	// 和值
	public Button hezhibtn01, hezhibtn02, hezhibtn03, hezhibtn04, hezhibtn05, hezhibtn06, hezhibtn07, hezhibtn08,
			hezhibtn09, hezhibtn10, hezhibtn11, hezhibtn12, hezhibtn13, hezhibtn14, hezhibtn15, hezhibtn16;
	public Button btn_3ttongxuan_3ltongxuan;
	public Button buy_kuai3_6btn_01, buy_kuai3_6btn_02, buy_kuai3_6btn_03, buy_kuai3_6btn_04, buy_kuai3_6btn_05,
			buy_kuai3_6btn_06;
	public Button buy_kuai3_t_01, buy_kuai3_t_02, buy_kuai3_t_03, buy_kuai3_t_04, buy_kuai3_t_05, buy_kuai3_t_06,
			buy_kuai3_bt_01, buy_kuai3_bt_02, buy_kuai3_bt_03, buy_kuai3_bt_04, buy_kuai3_bt_05, buy_kuai3_bt_06;
	private LinearLayout buy_kuai3_ll_hezhi, buy_kuai3ll_3ttongxuan_3ltongxuan, buy_kuai3_6btn,
			buy_kuai3_2tonghao_danxuan1, buy_kuai3_2tonghao_danxuan2;
	private Button buy_11x5_random;// 机选红球
	private Button buy_11x5_clear;// 清空选择
	private Button buy_11x5_submit;// 确认选择
	private TextView currentIssue;// 当前期次
	private TextView endTimeText;// 截至时间
	private TextView countText;// 倍数
	private TextView moneyText;
	private String strPlayType = "和值";
	private int lotID;
	private long endTime; // 剩余时间
	private int playTypeId = 6601;// 初始化默认和值
	private int count;
	private int allMoney;
	private String issueID; // 当前期次编号
	private String issueName;
	private PopupWindow m_popupWindow;
	/** 菜单弹出框 */
	private PopupWindow menu_popupWindow;
	/** 菜单弹出框 */
	private View menutypeview;
	/** 和值号码数组 */
	private DynArrayInt ball_hezhi_dintInt;
	/** 三同号通选 号码数组 */
	private DynArrayInt ball_3ttx_dintInt;
	/** 三连号通选 号码数组 */
	private DynArrayInt ball_3ltx_dintInt;
	/** 三同号单选 号码数组 */
	private DynArrayInt ball_6btn_dintInt;
	/** 二同号单选 号码数组 同号 */
	private DynArrayInt ball_2thdx1_dintInt;
	/** 二同号单选 号码数组 不同号 */
	private DynArrayInt ball_2thdx2_dintInt;
	Handler handler = new Handler();
	private SensorListener sensor;
	/** .若中奖：奖金0元，盈利0元 */
	private TextView tvJiangJin;
	/** 摇一摇机选一注视图 */
	private LinearLayout buy_ssq_llfoot0;
	/** 注数金额 */
	private RelativeLayout buy_ssq_rlfoot1;
	/** 点击此处可以弹出下拉10期开奖 */
	private LinearLayout buy_ssqxh_llxiala;
	/** 下拉10期开奖详情 */
	private LinearLayout buy_ssqxh_ll10kjdetail;
	/** 下拉10期开奖详情 */
	private List<Map<String, Object>> kjData;
	/** .至少选择几个号码 */
	private TextView buy_kuai3_6btn_tvnote;
	/** 奖金 */
	private int prizeIntellChase;
	/** 判断是否从选号列表过来 */
	private Boolean ifbacklist;
	/** 判断是否从推送通知过来 */
	private Boolean ifPush;
	private LinearLayout buy_ssqxh_Button03,buy_ssqxh_Button04;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.context = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.buy_kuai3);
		SysApplication.getInstance().addActivity(this);
		TitleBar();

		kaijiangAsyncLoader task = new kaijiangAsyncLoader();
		task.execute(LOT_ID_KUAI3 + "", "301");

		Intent intent = getIntent();
		lotID = LOT_ID_KUAI3;
		issueID = intent.getStringExtra("IssueID");
		issueName = intent.getStringExtra("IssueName");
		endTime = intent.getLongExtra("EndTime", 0);
		ifbacklist = intent.getBooleanExtra("ifbacklist", false);
		ifPush = intent.getBooleanExtra("ifPush", false);
		//Log.d("van", "ifbacklist---"+ifbacklist);
		playTypeId = intent.getIntExtra("playTypeId", 6601);
		if (playTypeId == 6601) {
			strPlayType = "和值";
		} else if (playTypeId == 6602) {
			strPlayType = "三同号通选";
		} else if (playTypeId == 6603) {
			strPlayType = "三连号通选";
		} else if (playTypeId == 6604) {
			strPlayType = "三同号单选";
		} else if (playTypeId == 6605) {
			strPlayType = "三不同号";
		} else if (playTypeId == 6606) {
			strPlayType = "二同号复选";
		} else if (playTypeId == 6607) {
			strPlayType = "二同号单选";
		} else if (playTypeId == 6608) {
			strPlayType = "二不同号";
		}
		initView();

		currentIssue.setText(issueName);

		handler.postDelayed(runnable, 1000);

		AsyncLoader task1 = new AsyncLoader();
		String[] parms = new String[2];
		parms[0] = "200";
		JSONObject jsob = new JSONObject();
		try {
			// 设置请求所需参数
			jsob.put("LottID", LOT_ID_KUAI3);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		parms[1] = jsob.toString();
		task1.execute(parms);

		// 下拉10期开奖
		buy_ssqxh_llxiala.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				doKaiJiang();
			}
		});

		buy_ssqxh_ll10kjdetail.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_ssqxh_ll10kjdetail.getVisibility() == View.VISIBLE) {
					buy_ssqxh_ll10kjdetail.setVisibility(View.GONE);
				}
			}
		});

		// 清空选择
		buy_11x5_clear.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

//				btnClearSelectData();
				initBall();
				allMoney = 0;
				count = 0;
				moneyText.setText("0");
				countText.setText("0");
				tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
				buy_ssq_llfoot0.setVisibility(View.VISIBLE);
				buy_ssq_rlfoot1.setVisibility(View.GONE);
			}
		});

		// 晃动手机机选号码
		sensor = new SensorListener(this);
		sensor.setOnSensorListener(new SensorListener.OnSensorListener() {
			@Override
			public void onShake() {
				// TODO Auto-generated method stub
				SoundManage.OnVibator(Kuai3Activity.this, 500);
				initRandomBall();
				// SoundManage.OnPlaySound(SsqxhActivity.this, "audio.mp3");
			}
		});

		// 机选
		buy_11x5_random.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				initRandomBall();
			}
		});

		// 确认选择，跳转至Kuai3ListActivity.class
		buy_11x5_submit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				
				goXhlbSubmit();
			}
		});

		if(!ifbacklist){
			initRandomBall();
		}
	}

	/**
	 * 开奖栏点击 事件
	 */
	protected void doKaiJiang() {
		if (kjData != null && buy_ssqxh_ll10kjdetail.getVisibility() == View.GONE) {
			buy_ssqxh_ll10kjdetail.setVisibility(View.VISIBLE);
			TextView buy_ssq_10qikj_tvqici1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici1);
			TextView buy_ssq_10qikj_tvqici2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici2);
			TextView buy_ssq_10qikj_tvqici3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici3);
			TextView buy_ssq_10qikj_tvqici4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici4);
			TextView buy_ssq_10qikj_tvqici5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici5);
			TextView buy_ssq_10qikj_tvqici6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici6);
			TextView buy_ssq_10qikj_tvqici7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici7);
			TextView buy_ssq_10qikj_tvqici8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici8);
			TextView buy_ssq_10qikj_tvqici9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici9);
			TextView buy_ssq_10qikj_tvqici10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici10);

			TextView buy_ssq_10qikj_tvred1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred1);
			TextView buy_ssq_10qikj_tvred2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred2);
			TextView buy_ssq_10qikj_tvred3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred3);
			TextView buy_ssq_10qikj_tvred4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred4);
			TextView buy_ssq_10qikj_tvred5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred5);
			TextView buy_ssq_10qikj_tvred6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred6);
			TextView buy_ssq_10qikj_tvred7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred7);
			TextView buy_ssq_10qikj_tvred8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred8);
			TextView buy_ssq_10qikj_tvred9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred9);
			TextView buy_ssq_10qikj_tvred10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred10);

			TextView buy_ssq_10qikj_tvblue1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue1);
			TextView buy_ssq_10qikj_tvblue2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue2);
			TextView buy_ssq_10qikj_tvblue3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue3);
			TextView buy_ssq_10qikj_tvblue4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue4);
			TextView buy_ssq_10qikj_tvblue5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue5);
			TextView buy_ssq_10qikj_tvblue6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue6);
			TextView buy_ssq_10qikj_tvblue7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue7);
			TextView buy_ssq_10qikj_tvblue8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue8);
			TextView buy_ssq_10qikj_tvblue9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue9);
			TextView buy_ssq_10qikj_tvblue10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue10);

			if (kjData != null && kjData.size() > 0) {
				buy_ssq_10qikj_tvqici1.setText(kjData.get(0).get("Issue").toString());
				buy_ssq_10qikj_tvred1.setText(kjData.get(0).get("Ball").toString());
				if (kjData.size() > 1) {
					buy_ssq_10qikj_tvqici2.setText(kjData.get(1).get("Issue").toString());
					buy_ssq_10qikj_tvred2.setText(kjData.get(1).get("Ball").toString());
				}
				if (kjData.size() > 2) {
					buy_ssq_10qikj_tvqici3.setText(kjData.get(2).get("Issue").toString());
					buy_ssq_10qikj_tvred3.setText(kjData.get(2).get("Ball").toString());
				}
				if (kjData.size() > 3) {
					buy_ssq_10qikj_tvqici4.setText(kjData.get(3).get("Issue").toString());
					buy_ssq_10qikj_tvred4.setText(kjData.get(3).get("Ball").toString());
				}
				if (kjData.size() > 4) {
					buy_ssq_10qikj_tvqici5.setText(kjData.get(4).get("Issue").toString());
					buy_ssq_10qikj_tvred5.setText(kjData.get(4).get("Ball").toString());
				}
				if (kjData.size() > 5) {
					buy_ssq_10qikj_tvqici6.setText(kjData.get(5).get("Issue").toString());
					buy_ssq_10qikj_tvred6.setText(kjData.get(5).get("Ball").toString());
				}
				if (kjData.size() > 6) {
					buy_ssq_10qikj_tvqici7.setText(kjData.get(6).get("Issue").toString());
					buy_ssq_10qikj_tvred7.setText(kjData.get(6).get("Ball").toString());
				}
				if (kjData.size() > 7) {
					buy_ssq_10qikj_tvqici8.setText(kjData.get(7).get("Issue").toString());
					buy_ssq_10qikj_tvred8.setText(kjData.get(7).get("Ball").toString());
				}
				if (kjData.size() > 8) {
					buy_ssq_10qikj_tvqici9.setText(kjData.get(8).get("Issue").toString());
					buy_ssq_10qikj_tvred9.setText(kjData.get(8).get("Ball").toString());
				}
				if (kjData.size() > 9) {
					buy_ssq_10qikj_tvqici10.setText(kjData.get(9).get("Issue").toString());
					buy_ssq_10qikj_tvred10.setText(kjData.get(9).get("Ball").toString());
				}

				if (kjData.get(0).get("BlueBall") != null && !"".equals(kjData.get(0).get("BlueBall").toString())) {
					buy_ssq_10qikj_tvblue1.setText(kjData.get(0).get("BlueBall").toString());
					if (kjData.size() > 1) {
						buy_ssq_10qikj_tvblue2.setText(kjData.get(1).get("BlueBall").toString());
					}
					if (kjData.size() > 2) {
						buy_ssq_10qikj_tvblue3.setText(kjData.get(2).get("BlueBall").toString());
					}
					if (kjData.size() > 3) {
						buy_ssq_10qikj_tvblue4.setText(kjData.get(3).get("BlueBall").toString());
					}
					if (kjData.size() > 4) {
						buy_ssq_10qikj_tvblue5.setText(kjData.get(4).get("BlueBall").toString());
					}
					if (kjData.size() > 5) {
						buy_ssq_10qikj_tvblue6.setText(kjData.get(5).get("BlueBall").toString());
					}
					if (kjData.size() > 6) {
						buy_ssq_10qikj_tvblue7.setText(kjData.get(6).get("BlueBall").toString());
					}
					if (kjData.size() > 7) {
						buy_ssq_10qikj_tvblue8.setText(kjData.get(7).get("BlueBall").toString());
					}
					if (kjData.size() > 8) {
						buy_ssq_10qikj_tvblue9.setText(kjData.get(8).get("BlueBall").toString());
					}
					if (kjData.size() > 9) {
						buy_ssq_10qikj_tvblue10.setText(kjData.get(9).get("BlueBall").toString());
					}
				} else {
					TextView buy_10qikj_tvfh1 = (TextView) findViewById(R.id.buy_10qikj_tvfh1);
					TextView buy_10qikj_tvfh2 = (TextView) findViewById(R.id.buy_10qikj_tvfh2);
					TextView buy_10qikj_tvfh3 = (TextView) findViewById(R.id.buy_10qikj_tvfh3);
					TextView buy_10qikj_tvfh4 = (TextView) findViewById(R.id.buy_10qikj_tvfh4);
					TextView buy_10qikj_tvfh5 = (TextView) findViewById(R.id.buy_10qikj_tvfh5);
					TextView buy_10qikj_tvfh6 = (TextView) findViewById(R.id.buy_10qikj_tvfh6);
					TextView buy_10qikj_tvfh7 = (TextView) findViewById(R.id.buy_10qikj_tvfh7);
					TextView buy_10qikj_tvfh8 = (TextView) findViewById(R.id.buy_10qikj_tvfh8);
					TextView buy_10qikj_tvfh9 = (TextView) findViewById(R.id.buy_10qikj_tvfh9);
					TextView buy_10qikj_tvfh10 = (TextView) findViewById(R.id.buy_10qikj_tvfh10);
					buy_10qikj_tvfh1.setVisibility(View.GONE);
					buy_10qikj_tvfh2.setVisibility(View.GONE);
					buy_10qikj_tvfh3.setVisibility(View.GONE);
					buy_10qikj_tvfh4.setVisibility(View.GONE);
					buy_10qikj_tvfh5.setVisibility(View.GONE);
					buy_10qikj_tvfh6.setVisibility(View.GONE);
					buy_10qikj_tvfh7.setVisibility(View.GONE);
					buy_10qikj_tvfh8.setVisibility(View.GONE);
					buy_10qikj_tvfh9.setVisibility(View.GONE);
					buy_10qikj_tvfh10.setVisibility(View.GONE);

					buy_ssq_10qikj_tvblue1.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue1.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue2.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue3.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue4.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue5.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue6.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue7.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue8.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue9.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue10.setVisibility(View.GONE);
				}
			}
		} else {
			buy_ssqxh_ll10kjdetail.setVisibility(View.GONE);
		}
	}

	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		sensor.stop();
		
	}

	protected void onResume() {
		sensor.start();
		handler.removeCallbacks(runnable);

		// TODO Auto-generated method stub
		AsyncLoader task = new AsyncLoader();
		String[] parms = new String[2];
		parms[0] = "200";
		JSONObject jsob = new JSONObject();
		try {
			// 设置请求所需参数
			jsob.put("LottID", LOT_ID_KUAI3);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		parms[1] = jsob.toString();
		task.execute(parms);

		handler.postDelayed(runnable, 1000);
		
		super.onResume();
	}

	public void sendIntent(BallDTO elvdto, String ball) {
		elvdto.setElv_ball(ball + "-" + allMoney);

		// 新选的号码，追加在ApplicationBall全局变量list_ssqdto里
		ApplicationData.getInstance().getList_11x5dto().add(elvdto);
		ApplicationData.getInstance().setAll_11x5money(ApplicationData.getInstance().getAll_11x5money() + allMoney);
		ApplicationData.getInstance().setPlay_11x5Id(playTypeId);

		Intent intent = new Intent();
		intent.putExtra("list_elvdto", ApplicationData.getInstance().getList_11x5dto());
		intent.putExtra("PlayTypeID", playTypeId);
		intent.putExtra("PlayType", strPlayType);
		intent.putExtra("AllMoney", ApplicationData.getInstance().getAll_11x5money());
		intent.putExtra("LotID", lotID);
		intent.putExtra("Count", count);
		intent.putExtra("IssueID", issueID);
		intent.putExtra("IssueName", issueName);
		intent.putExtra("prizeIntellChase", prizeIntellChase);
		intent.setClass(Kuai3Activity.this, Kuai3ListActivity.class);
		startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
		finish();
	}

	// 倒计时
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			getCountDown(endTime--);
			handler.postDelayed(this, 1000);
			// if(endTime%5==0){
			// Log.v("Kuai3Activity", "runnable endTime= "+endTime);
			// }

		}
	};

	private void getCountDown(long end) {
		if (end > 0) {
			String res = "";
			long temp = 0;
			long d = end / 86400;
			temp = end - (d * 86400);
			if (d > 0) {
				res += d + "天";
			}

			long h = temp / 3600;
			if (h > 0) {
				res += h + "时";
			}
			temp = temp - (h * 3600);

			long m = temp / 60;
			if (m > 0) {
				res += m + "分";
			}
			temp = temp - (m * 60);

			long s = temp;
			res += s + "秒";
			endTimeText.setText(res);
		} else {
			endTimeText.setText("----------");

			AsyncLoader task = new AsyncLoader();
			String[] parms = new String[2];
			parms[0] = "200";
			JSONObject jsob = new JSONObject();
			try {
				// 设置请求所需参数
				jsob.put("LottID", LOT_ID_KUAI3);
			} catch (JSONException ex) {
				// TODO Auto-generated catch block
				Log.e("error", ex.toString());
			}
			parms[1] = jsob.toString();
			task.execute(parms);
		}
	}

	private List<Map<String, Object>> mData;
	private Map<String, Object> cData;

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		int id;

		// 1.准备运行
		protected void onPreExecute() {
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... params) {
			// 处理后台执行的任务，在后台线程执行
			String strResult;
			// String param = new String();
			// 设置请求action
			String action = params[0];
			// 获取请求返回值
			strResult = GetRequestParams.getRequestResult(params[1], action, getApplicationContext());
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				mData = getData(result);
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						for (int i = 0; i < mData.size(); i++) {
							id = Integer.parseInt(mData.get(i).get("LotID").toString());
							cData = mData.get(i);
							switch (id) {
							case LOT_ID_KUAI3:
								issueID = cData.get("IssueID").toString();
								issueName = cData.get("IssueName").toString();
								endTime = setEndTime(cData);
								currentIssue.setText(issueName);
							}
						}
					} else {
						Toast.makeText(Kuai3Activity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				}
			} else {
				Toast.makeText(Kuai3Activity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
				return;
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}
	}

	/**
	 * 
	 * 获取开奖数据
	 * 
	 */
	public class kaijiangAsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		// 1.准备运行
		protected void onPreExecute() {
			// showdialog.showDialog(KjinfoListByType.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... params) {
			String strResult;
			try {
				// 处理后台执行的任务，在后台线程执行
				JSONObject param = new JSONObject();
				param.put("LottID", params[0]);
				// 设置请求action
				String action = params[1];
				// 获取请求返回值
				strResult = GetRequestParams.getRequestResult(param.toString(), action, getApplicationContext());
				return strResult;
			} catch (Exception e) {
				// TODO: handle exception
				Log.e("error", e.toString());
				return null;
			}
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				// Toast.LENGTH_LONG).show();
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						if (!"".equals(js.getString("Data"))) {
							kjData = getData(result);
							for (int i = 0; i < kjData.size(); i++) {
								String issue = kjData.get(i).get("Issue").toString();
								issue += "期";// = "期\t开奖号码"
								kjData.get(i).put("Issue", issue);
								String winNumber = kjData.get(i).get("WinNumber").toString();
								String[] nums = winNumber.split("\\+");
								// kjData.get(i).put("Ball", nums[0]);
								kjData.get(i).put("Ball", nums[0].replaceAll(",", " "));
								kjData.get(i).put("BlueBall", nums.length > 1 ? nums[1].trim() : "");
							}
							// Log.v("kuai3xh", "kjData= "+kjData.toString());
							// KjInfoListAdapter adapter = new
							// KjInfoListAdapter(Fc3dxhActivity.this, mData);
							// buy_11x5_lv_kaijiang.setAdapter(adapter);
						} else {
						}
						// showdialog.closeDialog();
					} else {
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					// showdialog.closeDialog();
				}
			} else {
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}

	private List<Map<String, Object>> getData(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			list = ConvertJsonToList.getList(js.getString("Data"));
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}

		return list;
	}

	private Map<String, Object> getCurrentData(String strResult, String key) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			map = ConvertJsonToList.getMap(js.getString(key));
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}

		return map;
	}

	private long setEndTime(Map<String, Object> data) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long endTime = 0;
		try {
			long a = sdf.parse(data.get("CurrentTime").toString()).getTime();
			long b = sdf.parse(data.get("EndTime").toString()).getTime();
			endTime = (b - a) / 1000;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
		return endTime;
	}

	private void initView() {
		buy_ssq_llfoot0 = (LinearLayout) findViewById(R.id.buy_ssq_llfoot0);
		buy_ssq_rlfoot1 = (RelativeLayout) findViewById(R.id.buy_ssq_rlfoot1);
		buy_ssqxh_llxiala = (LinearLayout) findViewById(R.id.buy_ssqxh_llxiala);
		buy_ssqxh_ll10kjdetail = (LinearLayout) findViewById(R.id.buy_ssqxh_ll10kjdetail);
		buy_ssq_llfoot0.setVisibility(View.VISIBLE);
		buy_ssq_rlfoot1.setVisibility(View.GONE);
		// 改变第一个框的背景，得到该对象
		buy_kuai3_ll_hezhi = (LinearLayout) findViewById(R.id.buy_kuai3_ll_hezhi);
		buy_kuai3ll_3ttongxuan_3ltongxuan = (LinearLayout) findViewById(R.id.buy_kuai3ll_3ttongxuan_3ltongxuan);
		buy_kuai3_6btn = (LinearLayout) findViewById(R.id.buy_kuai3_6btn);
		buy_kuai3_2tonghao_danxuan1 = (LinearLayout) findViewById(R.id.buy_kuai3_2tonghao_danxuan1);
		buy_kuai3_2tonghao_danxuan2 = (LinearLayout) findViewById(R.id.buy_kuai3_2tonghao_danxuan2);

		buy_kuai3_6btn_tvnote = (TextView) findViewById(R.id.buy_kuai3_6btn_tvnote);
		// 初始化球
		initBall();
		// 初始化文本框
		initText();

		// 初始化button
		initButton();

		// // 初始化下拉框
		initSelectPlayTypeView();
	}

	/**
	 * 机选及晃动手机
	 */
	public void initRandomBall() {
		initBall();
		ball_hezhi_dintInt = new DynArrayInt();
		ball_3ttx_dintInt = new DynArrayInt();
		ball_3ltx_dintInt = new DynArrayInt();
		ball_6btn_dintInt = new DynArrayInt();
		ball_2thdx1_dintInt = new DynArrayInt();
		ball_2thdx2_dintInt = new DynArrayInt();

		ball_hezhi_dintInt.removeAll();
		ball_3ttx_dintInt.removeAll();
		ball_3ltx_dintInt.removeAll();
		ball_6btn_dintInt.removeAll();
		ball_2thdx1_dintInt.removeAll();
		ball_2thdx2_dintInt.removeAll();

		if (playTypeId == 6601) {
			// 开始随机号码
			int ball_random[] = RandomGenData(3, 18, getRandomNum(playTypeId), "first");
			for (int i = 0; i < ball_random.length; i++) {
				if (ball_random[i] == 3) {
					ball_random[i] = 111;
				}
				if (ball_random[i] == 18) {
					ball_random[i] = 666;
				}
			}
			// 追加数组到ball_1st_dintInt中,和值3是111
			ball_hezhi_dintInt.addInt(ball_random);
		} else if (playTypeId == 6602) {
			ball_3ttx_dintInt.addInt(1);
			btn_3ttongxuan_3ltongxuan.setSelected(true);
		} else if (playTypeId == 6603) {
			ball_3ltx_dintInt.addInt(1);
			btn_3ttongxuan_3ltongxuan.setSelected(true);
		} else if (playTypeId == 6604 || playTypeId == 6605 || playTypeId == 6606 || playTypeId == 6608) {
			// 开始随机号码
			int ball_random[] = RandomGenData(1, 6, getRandomNum(playTypeId), "first");
			// 追加数组到ball_6btn_dintInt中,6606二同号复选 6608 二不同号
			ball_6btn_dintInt.addInt(ball_random);
		} else if (playTypeId == 6607) {
			randomDirectTwo();
		}

		getMoneyInfo();
	}

	public void initBall() {
		// 和值初始化球
		initHeZhiBall();

		if (playTypeId == 6602) {
			// 三同号通选
			init3TongHaoTXBall();
		} else if (playTypeId == 6603) {
			// 三连号通选
			init3LianHaoTXBall();
		}
		// // 三同号单选
		// init3TongHaoDXBall(6604);//三同号单选
		// init3TongHaoDXBall(6605);//三不同号
		// init3TongHaoDXBall(6606);//二同号复选
		// init3TongHaoDXBall(6608);// 二不同号

		init3TongHaoDXBall(playTypeId);

		// 二同号单选
		init2TongHaoDXBall1();
		init2TongHaoDXBall2();
	}

	/**
	 * 二同号单选 机选随机选号
	 * 
	 * @return
	 */
	public String randomDirectTwo() {
		String ball = "";
		int first_ball[] = RandomGenData2THDX(1, 6);
		int second_ball[] = RandomGenData2THDX(1, 6);
		// 判断是否有重复数字
		if (first_ball[0] == second_ball[0]) {
			initBall();
			randomDirectTwo();
		} else {
			ball_2thdx1_dintInt = new DynArrayInt();
			ball_2thdx2_dintInt = new DynArrayInt();

			ball_2thdx1_dintInt.removeAll();
			ball_2thdx2_dintInt.removeAll();

			ball_2thdx1_dintInt.addInt(first_ball);
			ball_2thdx2_dintInt.addInt(second_ball);
			String first = ball_2thdx1_dintInt.getIntToStringForSingle(0);
			BallRandom2THDX(1, 0, Integer.parseInt(first));
			String second = ball_2thdx2_dintInt.getIntToStringForSingle(0);
			BallRandom2THDX(0, 1, Integer.parseInt(second));
			ball = first + "#" + second;// first + "|" + second; 3 33
		}
		// Log.v("kuai3", "randomDirectTwo ball= " + ball);
		return ball;
	}

	/**
	 * 二同号单选 机选随机取数
	 * 
	 * @param min
	 *            最小值
	 * @param max
	 *            最大值
	 * @return 一个随机数
	 */
	public int[] RandomGenData2THDX(int min, int max) {
		int[] temp;
		Random rndNumber;
		rndNumber = new Random();
		temp = new int[1];
		List<Integer> a1 = new ArrayList<Integer>();

		for (int i = min; i <= max; i++) {
			a1.add((Integer) i);
		}

		int index = rndNumber.nextInt(max - min + 1);
		Object o = a1.get(index);
		temp[0] = ((Integer) o).intValue();

		a1.remove(index);

		Arrays.sort(temp);
		// Log.d("kuai3", "RandomGenData2THDX temp[0]= "+temp[0]);
		return temp;
	}

	/**
	 * 随机取球，并显示
	 * 
	 * @param min
	 *            开始值
	 * @param max
	 *            结束值
	 * @param num
	 *            随机数个数
	 * @param position
	 *            位置
	 * @return 随机数数组
	 */
	public int[] RandomGenData(int min, int max, int num, String position) {
		int[] temp;
		Random rndNumber;
		rndNumber = new Random();
		temp = new int[num];
		List<Integer> a1 = new ArrayList<Integer>();

		for (int i = min; i <= max; i++) {
			a1.add((Integer) i);
		}
		for (int i = 0; i < num; i++) {
			int index = rndNumber.nextInt(max - min + 1 - i);
			Object o = a1.get(index);
			temp[i] = ((Integer) o).intValue();
			if (position.equals("first"))
				// Log.v("kuai3", "RandomGenData first temp[i]= "+temp[i]);
				if (playTypeId == 6604 || playTypeId == 6605 || playTypeId == 6606 || playTypeId == 6608) {
					BallRandom6btn(1, 0, 0, temp[i]);
				} else {
					BallRandom(1, 0, 0, temp[i]);
				}

			a1.remove(index);
		}
		Arrays.sort(temp);
		return temp;
	}

	// 显示注数和金钱
	public void getMoneyInfo() {
		int money;
		// 奖金
		int totalmoney = 0;
		count = 0;
		switch (playTypeId) {
		case 6601:
			int a = ball_hezhi_dintInt.getSize();
			count += a;
			break;
		case 6602:// //三同号通选
			int b = ball_3ttx_dintInt.getSize();
			count += b;
			totalmoney = 40;
			break;
		case 6603:// 三连号通选
			int c = ball_3ltx_dintInt.getSize();
			count += c;
			totalmoney = 10;
			break;
		case 6604:// 三同号单选
			int d = ball_6btn_dintInt.getSize();
			count += d;
			totalmoney = 240;
			break;
		case 6605:// 三不同号
			int e = ball_6btn_dintInt.getSize();
			if (e < 3) {
				count = 0;
			} else if (e == 3) {
				count = 1;
			} else if (e == 4) {
				count = 4;
			} else if (e == 5) {
				count = 10;
			} else if (e == 6) {
				count = 20;
			}
			totalmoney = 40;
			break;
		case 6606:
			int f = ball_6btn_dintInt.getSize();
			count += f;
			totalmoney = 15;
			break;
		case 6607:
			// 计算注数，代表的三个数字都相等时不算
			for (int c1 : ball_2thdx1_dintInt.getAllInt()) {
				for (int c2 : ball_2thdx2_dintInt.getAllInt()) {
					if (c2 != c1) {
						count++;
					}
				}
			}
			totalmoney = 80;
			break;
		case 6608:// 二不同号
			int h = ball_6btn_dintInt.getSize();
			if (h < 2) {
				count = 0;
			} else if (h == 2) {
				count = 1;
			} else if (h == 3) {
				count = 3;
			} else if (h == 4) {
				count = 6;
			} else if (h == 5) {
				count = 10;
			} else if (h == 6) {
				count = 15;
			}
			totalmoney = 8;
			break;
		}
		money = count * 2;
		allMoney = money;
		countText.setText(count + "");
		moneyText.setText(Html.fromHtml("<font color='#fe5052'>"+money+"</font>" + " 元"));
		// 计算总奖金
		if (money == 0) {
			tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
		} else {
			String strjiangjin = "";
			if (playTypeId == 6601) {
				String strhezhi = Kuai3Util.getkuai3HeZhiJiangJin(ball_hezhi_dintInt.getAllInt());
				int min = Integer.parseInt((strhezhi.split("\\|")[0]));
				int max = Integer.parseInt((strhezhi.split("\\|")[1]));
					prizeIntellChase = max;
				if (min == max) {
					strjiangjin = ".若中奖：奖金" + max + "元，盈利" + (max - money) + "元";
				} else {
					strjiangjin = ".若中奖：奖金" + min + "~" + max + "元，盈利" + (min - money) + "~" + (max - money) + "元";
				}
			} else {
					prizeIntellChase = totalmoney;
				strjiangjin = ".若中奖：奖金" + totalmoney + "元，盈利" + (totalmoney - money) + "元";
			}
			tvJiangJin.setText(strjiangjin);
		}
		if (count == 0) {
			buy_ssq_llfoot0.setVisibility(View.VISIBLE);
			buy_ssq_rlfoot1.setVisibility(View.GONE);
		} else {
			buy_ssq_llfoot0.setVisibility(View.GONE);
			buy_ssq_rlfoot1.setVisibility(View.VISIBLE);
		}
	}

	/**
	 * 和值玩法 投注球号码显示状态
	 * 
	 * @param a
	 * @param b
	 * @param c
	 * @param num
	 */
	public void BallRandom(int a, int b, int c, int num) {
		// Log.v("kuai3", "BallRandom num= " + num + " ,a= " + a);
		if (num == 3 && a == 1) {
			hezhibtn01.setSelected(true);
			hezhibtn01.setText(Html
					.fromHtml("<font color='#ffffff'><big>3</big></font><br> <font color='#ffffff'>奖金240</font>"));
		}
		if (num == 4 && a == 1) {
			hezhibtn02.setSelected(true);
			hezhibtn02.setText(Html
					.fromHtml("<font color='#ffffff'><big>4</big></font><br> <font color='#ffffff'>奖金80</font>"));
		}
		if (num == 5 && a == 1) {
			hezhibtn03.setSelected(true);
			hezhibtn03.setText(Html
					.fromHtml("<font color='#ffffff'><big>5</big></font><br> <font color='#ffffff'>奖金40</font>"));
		}
		if (num == 6 && a == 1) {
			hezhibtn04.setSelected(true);
			hezhibtn04.setText(Html
					.fromHtml("<font color='#ffffff'><big>6</big></font><br> <font color='#ffffff'>奖金25</font>"));
		}
		if (num == 7 && a == 1) {
			hezhibtn05.setSelected(true);
			hezhibtn05.setText(Html
					.fromHtml("<font color='#ffffff'><big>7</big></font><br> <font color='#ffffff'>奖金16</font>"));
		}
		if (num == 8 && a == 1) {
			hezhibtn06.setSelected(true);
			hezhibtn06.setText(Html
					.fromHtml("<font color='#ffffff'><big>8</big></font><br> <font color='#ffffff'>奖金12</font>"));
		}
		if (num == 9 && a == 1) {
			hezhibtn07.setSelected(true);
			hezhibtn07.setText(Html
					.fromHtml("<font color='#ffffff'><big>9</big></font><br> <font color='#ffffff'>奖金10</font>"));
		}
		if (num == 10 && a == 1) {
			hezhibtn08.setSelected(true);
			hezhibtn08.setText(Html
					.fromHtml("<font color='#ffffff'><big>10</big></font><br> <font color='#ffffff'>奖金9</font>"));
		}
		if (num == 11 && a == 1) {
			hezhibtn09.setSelected(true);
			hezhibtn09.setText(Html
					.fromHtml("<font color='#ffffff'><big>11</big></font><br> <font color='#ffffff'>奖金9</font>"));
		}
		if (num == 12 && a == 1) {
			hezhibtn10.setSelected(true);
			hezhibtn10.setText(Html
					.fromHtml("<font color='#ffffff'><big>12</big></font><br> <font color='#ffffff'>奖金10</font>"));
		}
		if (num == 13 && a == 1) {
			hezhibtn11.setSelected(true);
			hezhibtn11.setText(Html
					.fromHtml("<font color='#ffffff'><big>13</big></font><br> <font color='#ffffff'>奖金12</font>"));
		}
		if (num == 14 && a == 1) {
			hezhibtn12.setSelected(true);
			hezhibtn12.setText(Html
					.fromHtml("<font color='#ffffff'><big>14</big></font><br> <font color='#ffffff'>奖金16</font>"));
		}
		if (num == 15 && a == 1) {
			hezhibtn13.setSelected(true);
			hezhibtn13.setText(Html
					.fromHtml("<font color='#ffffff'><big>15</big></font><br> <font color='#ffffff'>奖金25</font>"));
		}
		if (num == 16 && a == 1) {
			hezhibtn14.setSelected(true);
			hezhibtn14.setText(Html
					.fromHtml("<font color='#ffffff'><big>16</big></font><br> <font color='#ffffff'>奖金40</font>"));
		}
		if (num == 17 && a == 1) {
			hezhibtn15.setSelected(true);
			hezhibtn15.setText(Html
					.fromHtml("<font color='#ffffff'><big>17</big></font><br> <font color='#ffffff'>奖金80</font>"));
		}
		if (num == 18 && a == 1) {
			hezhibtn16.setSelected(true);
			hezhibtn16.setText(Html
					.fromHtml("<font color='#ffffff'><big>18</big></font><br> <font color='#ffffff'>奖金240</font>"));
		}
	}

	/**
	 * 三同号单选 机选按钮状态变化显示
	 * 
	 * @param a
	 * @param b
	 * @param c
	 * @param num
	 */
	public void BallRandom6btn(int a, int b, int c, int num) {
		if (num == 1 && a == 1) {
			buy_kuai3_6btn_01.setSelected(true);
		}
		if (num == 2 && a == 1) {
			buy_kuai3_6btn_02.setSelected(true);
		}
		if (num == 3 && a == 1) {
			buy_kuai3_6btn_03.setSelected(true);
		}
		if (num == 4 && a == 1) {
			buy_kuai3_6btn_04.setSelected(true);
		}
		if (num == 5 && a == 1) {
			buy_kuai3_6btn_05.setSelected(true);
		}
		if (num == 6 && a == 1) {
			buy_kuai3_6btn_06.setSelected(true);
		}
	}

	/**
	 * 二同号单选 机选按钮状态变化显示
	 * 
	 * @param a
	 *            同号
	 * @param b
	 *            不 同号
	 * @param num
	 *            位置
	 */
	public void BallRandom2THDX(int a, int b, int num) {
		if (num == 1 && a == 1) {
			buy_kuai3_t_01.setSelected(true);
		}
		if (num == 2 && a == 1) {
			buy_kuai3_t_02.setSelected(true);
		}
		if (num == 3 && a == 1) {
			buy_kuai3_t_03.setSelected(true);
		}
		if (num == 4 && a == 1) {
			buy_kuai3_t_04.setSelected(true);
		}
		if (num == 5 && a == 1) {
			buy_kuai3_t_05.setSelected(true);
		}
		if (num == 6 && a == 1) {
			buy_kuai3_t_06.setSelected(true);
		}
		// 不 同号选择
		if (num == 1 && b == 1) {
			buy_kuai3_bt_01.setSelected(true);
		}
		if (num == 2 && b == 1) {
			buy_kuai3_bt_02.setSelected(true);
		}
		if (num == 3 && b == 1) {
			buy_kuai3_bt_03.setSelected(true);
		}
		if (num == 4 && b == 1) {
			buy_kuai3_bt_04.setSelected(true);
		}
		if (num == 5 && b == 1) {
			buy_kuai3_bt_05.setSelected(true);
		}
		if (num == 6 && b == 1) {
			buy_kuai3_bt_06.setSelected(true);
		}
	}

	private int getRandomNum(int typeId) {
		int num = 0;
		switch (typeId) {
		case 6601:
		case 6602:
		case 6603:
		case 6604:
		case 6606:
			num = 1;
			break;
		case 6605:// 三不同号 随机取3个数做随机号码
			num = 3;
			break;
		// case 6607:
		// num = 1;
		// break;
		case 6608:
			num = 2;
			break;
		}
		return num;
	}

	// Button初始化
	public void initButton() {
		buy_ssqxh_Button03 = (LinearLayout) findViewById(R.id.buy_ssqxh_Button03);
		buy_ssqxh_Button04 = (LinearLayout) findViewById(R.id.buy_ssqxh_Button04);
		buy_11x5_random = (Button) findViewById(R.id.buy_11x5_random);// 机选
		buy_11x5_clear = (Button) findViewById(R.id.buy_11x5_clear);// 清空选择
		buy_11x5_submit = (Button) findViewById(R.id.buy_11x5_submit);// 确认选择
	}

	private void initText() {
		currentIssue = (TextView) findViewById(R.id.buy_11x5_currentissue);
		endTimeText = (TextView) findViewById(R.id.buy_11x5_endtime);
		endTimeText.setText("--------------");
		// modeDES = (TextView) findViewById(R.id.buy_11x5_mode_des);
		countText = (TextView) findViewById(R.id.buy_11x5_count);
		moneyText = (TextView) findViewById(R.id.buy_11x5_amount);
		tvJiangJin = (TextView) findViewById(R.id.tvJiangJin);
		// currentIssue.setText(mData.get("IssueName").toString());
		// endTime.setText(mData.get("EndTime").toString());
	}

	/**
	 * 和值
	 */
	public void initHeZhiBall() {
		ball_hezhi_dintInt = new DynArrayInt();

		hezhibtn01 = (Button) findViewById(R.id.buy_kuai3_hezhi01);
		hezhibtn01.setSelected(false);
		// hezhibtn01.setText(Html.fromHtml("<font color='#333333'><big>3</big></font><br> <font size='8' color='#777777'>奖金240</font>"));//3\n奖金240
		hezhibtn01.setText(Html
				.fromHtml("<font color='#333333'><big>3</big></font><br> <font color='#777777'>奖金240</font>"));
		hezhibtn01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn01.isSelected()) {
					hezhibtn01.setSelected(false);
					ball_hezhi_dintInt.remove(111);// 3 111
					// hezhibtn01.setText(Html.fromHtml("<font color='#333333'><big>3</big></font><br> <font size='8' color='#777777'>奖金240</font>"));
					hezhibtn01.setText(Html
							.fromHtml("<font color='#333333'><big>3</big></font><br> <font color='#777777'>奖金240</font>"));
				} else {
					hezhibtn01.setSelected(true);
					ball_hezhi_dintInt.addInt(111);// 3 111
					// hezhibtn01.setText(Html.fromHtml("<font color='#ffffff'><big>3</big></font><br> <font size='15' color='#ffffff'>奖金240</font>"));
					hezhibtn01.setText(Html
							.fromHtml("<font color='#ffffff'><big>3</big></font><br> <font color='#ffffff'>奖金240</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn02 = (Button) findViewById(R.id.buy_kuai3_hezhi02);
		hezhibtn02.setSelected(false);
		// hezhibtn02.setText("4\n奖金80");
		hezhibtn02.setText(Html
				.fromHtml("<font color='#333333'><big>4</big></font><br> <font color='#777777'>奖金80</font>"));
		hezhibtn02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn02.isSelected()) {
					hezhibtn02.setSelected(false);
					ball_hezhi_dintInt.remove(4);
					hezhibtn02.setText(Html
							.fromHtml("<font color='#333333'><big>4</big></font><br> <font color='#777777'>奖金80</font>"));
				} else {
					hezhibtn02.setSelected(true);
					ball_hezhi_dintInt.addInt(4);
					hezhibtn02.setText(Html
							.fromHtml("<font color='#ffffff'><big>4</big></font><br> <font color='#ffffff'>奖金80</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn03 = (Button) findViewById(R.id.buy_kuai3_hezhi03);
		hezhibtn03.setSelected(false);
		// hezhibtn03.setText("5\n奖金40");
		hezhibtn03.setText(Html
				.fromHtml("<font color='#333333'><big>5</big></font><br> <font color='#777777'>奖金40</font>"));
		hezhibtn03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn03.isSelected()) {
					hezhibtn03.setSelected(false);
					ball_hezhi_dintInt.remove(5);
					hezhibtn03.setText(Html
							.fromHtml("<font color='#333333'><big>5</big></font><br> <font color='#777777'>奖金40</font>"));
				} else {
					hezhibtn03.setSelected(true);
					ball_hezhi_dintInt.addInt(5);
					hezhibtn03.setText(Html
							.fromHtml("<font color='#ffffff'><big>5</big></font><br> <font color='#ffffff'>奖金40</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn04 = (Button) findViewById(R.id.buy_kuai3_hezhi04);
		hezhibtn04.setSelected(false);
		// hezhibtn04.setText("6\n奖金25");
		hezhibtn04.setText(Html
				.fromHtml("<font color='#333333'><big>6</big></font><br> <font color='#777777'>奖金25</font>"));
		hezhibtn04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn04.isSelected()) {
					hezhibtn04.setSelected(false);
					ball_hezhi_dintInt.remove(6);
					hezhibtn04.setText(Html
							.fromHtml("<font color='#333333'><big>6</big></font><br> <font color='#777777'>奖金25</font>"));
				} else {
					hezhibtn04.setSelected(true);
					ball_hezhi_dintInt.addInt(6);
					hezhibtn04.setText(Html
							.fromHtml("<font color='#ffffff'><big>6</big></font><br> <font color='#ffffff'>奖金25</font>"));
				}
				getMoneyInfo();
			}
		});
		hezhibtn05 = (Button) findViewById(R.id.buy_kuai3_hezhi05);
		hezhibtn05.setSelected(false);
		// hezhibtn05.setText("7\n奖金16");
		hezhibtn05.setText(Html
				.fromHtml("<font color='#333333'><big>7</big></font><br> <font color='#777777'>奖金16</font>"));
		hezhibtn05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn05.isSelected()) {
					hezhibtn05.setSelected(false);
					ball_hezhi_dintInt.remove(7);
					hezhibtn05.setText(Html
							.fromHtml("<font color='#333333'><big>7</big></font><br> <font color='#777777'>奖金16</font>"));
				} else {
					hezhibtn05.setSelected(true);
					ball_hezhi_dintInt.addInt(7);
					hezhibtn05.setText(Html
							.fromHtml("<font color='#ffffff'><big>7</big></font><br> <font color='#ffffff'>奖金16</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn06 = (Button) findViewById(R.id.buy_kuai3_hezhi06);
		hezhibtn06.setSelected(false);
		// hezhibtn06.setText("8\n奖金12");
		hezhibtn06.setText(Html
				.fromHtml("<font color='#333333'><big>8</big></font><br> <font color='#777777'>奖金12</font>"));
		hezhibtn06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn06.isSelected()) {
					hezhibtn06.setSelected(false);
					ball_hezhi_dintInt.remove(8);
					hezhibtn06.setText(Html
							.fromHtml("<font color='#333333'><big>8</big></font><br> <font color='#777777'>奖金12</font>"));
				} else {
					hezhibtn06.setSelected(true);
					ball_hezhi_dintInt.addInt(8);
					hezhibtn06.setText(Html
							.fromHtml("<font color='#ffffff'><big>8</big></font><br> <font color='#ffffff'>奖金12</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn07 = (Button) findViewById(R.id.buy_kuai3_hezhi07);
		hezhibtn07.setSelected(false);
		// hezhibtn07.setText("9\n奖金10");
		hezhibtn07.setText(Html
				.fromHtml("<font color='#333333'><big>9</big></font><br> <font color='#777777'>奖金10</font>"));
		hezhibtn07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn07.isSelected()) {
					hezhibtn07.setSelected(false);
					ball_hezhi_dintInt.remove(9);
					hezhibtn07.setText(Html
							.fromHtml("<font color='#333333'><big>9</big></font><br> <font color='#777777'>奖金10</font>"));
				} else {
					hezhibtn07.setSelected(true);
					ball_hezhi_dintInt.addInt(9);
					hezhibtn07.setText(Html
							.fromHtml("<font color='#ffffff'><big>9</big></font><br> <font color='#ffffff'>奖金10</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn08 = (Button) findViewById(R.id.buy_kuai3_hezhi08);
		hezhibtn08.setSelected(false);
		// hezhibtn08.setText("10\n奖金9");
		hezhibtn08.setText(Html
				.fromHtml("<font color='#333333'><big>10</big></font><br> <font color='#777777'>奖金9</font>"));
		hezhibtn08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn08.isSelected()) {
					hezhibtn08.setSelected(false);
					ball_hezhi_dintInt.remove(10);
					hezhibtn08.setText(Html
							.fromHtml("<font color='#333333'><big>10</big></font><br> <font color='#777777'>奖金9</font>"));
				} else {
					hezhibtn08.setSelected(true);
					ball_hezhi_dintInt.addInt(10);
					hezhibtn08.setText(Html
							.fromHtml("<font color='#ffffff'><big>10</big></font><br> <font color='#ffffff'>奖金9</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn09 = (Button) findViewById(R.id.buy_kuai3_hezhi09);
		hezhibtn09.setSelected(false);
		// hezhibtn09.setText("11\n奖金9");
		hezhibtn09.setText(Html
				.fromHtml("<font color='#333333'><big>11</big></font><br> <font color='#777777'>奖金9</font>"));
		hezhibtn09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn09.isSelected()) {
					hezhibtn09.setSelected(false);
					ball_hezhi_dintInt.remove(11);
					hezhibtn09.setText(Html
							.fromHtml("<font color='#333333'><big>11</big></font><br> <font color='#777777'>奖金9</font>"));
				} else {
					hezhibtn09.setSelected(true);
					ball_hezhi_dintInt.addInt(11);
					hezhibtn09.setText(Html
							.fromHtml("<font color='#ffffff'><big>11</big></font><br> <font color='#ffffff'>奖金9</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn10 = (Button) findViewById(R.id.buy_kuai3_hezhi10);
		hezhibtn10.setSelected(false);
		// hezhibtn10.setText("12\n奖金10");
		hezhibtn10.setText(Html
				.fromHtml("<font color='#333333'><big>12</big></font><br> <font color='#777777'>奖金10</font>"));
		hezhibtn10.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn10.isSelected()) {
					hezhibtn10.setSelected(false);
					ball_hezhi_dintInt.remove(12);
					hezhibtn10.setText(Html
							.fromHtml("<font color='#333333'><big>12</big></font><br> <font color='#777777'>奖金10</font>"));
				} else {
					hezhibtn10.setSelected(true);
					ball_hezhi_dintInt.addInt(12);
					hezhibtn10.setText(Html
							.fromHtml("<font color='#ffffff'><big>12</big></font><br> <font color='#ffffff'>奖金10</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn11 = (Button) findViewById(R.id.buy_kuai3_hezhi11);
		hezhibtn11.setSelected(false);
		// hezhibtn11.setText("13\n奖金12");
		hezhibtn11.setText(Html
				.fromHtml("<font color='#333333'><big>13</big></font><br> <font color='#777777'>奖金12</font>"));
		hezhibtn11.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn11.isSelected()) {
					hezhibtn11.setSelected(false);
					ball_hezhi_dintInt.remove(13);
					hezhibtn11.setText(Html
							.fromHtml("<font color='#333333'><big>13</big></font><br> <font color='#777777'>奖金12</font>"));
				} else {
					hezhibtn11.setSelected(true);
					ball_hezhi_dintInt.addInt(13);
					hezhibtn11.setText(Html
							.fromHtml("<font color='#ffffff'><big>13</big></font><br> <font color='#ffffff'>奖金12</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn12 = (Button) findViewById(R.id.buy_kuai3_hezhi12);
		hezhibtn12.setSelected(false);
		// hezhibtn12.setText("14\n奖金16");
		hezhibtn12.setText(Html
				.fromHtml("<font color='#333333'><big>14</big></font><br> <font color='#777777'>奖金16</font>"));
		hezhibtn12.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn12.isSelected()) {
					hezhibtn12.setSelected(false);
					ball_hezhi_dintInt.remove(14);
					hezhibtn12.setText(Html
							.fromHtml("<font color='#333333'><big>14</big></font><br> <font color='#777777'>奖金16</font>"));
				} else {
					hezhibtn12.setSelected(true);
					ball_hezhi_dintInt.addInt(14);
					hezhibtn12.setText(Html
							.fromHtml("<font color='#ffffff'><big>14</big></font><br> <font color='#ffffff'>奖金16</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn13 = (Button) findViewById(R.id.buy_kuai3_hezhi13);
		hezhibtn13.setSelected(false);
		// hezhibtn13.setText("15\n奖金25");
		hezhibtn13.setText(Html
				.fromHtml("<font color='#333333'><big>15</big></font><br> <font color='#777777'>奖金25</font>"));
		hezhibtn13.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn13.isSelected()) {
					hezhibtn13.setSelected(false);
					ball_hezhi_dintInt.remove(15);
					hezhibtn13.setText(Html
							.fromHtml("<font color='#333333'><big>15</big></font><br> <font color='#777777'>奖金25</font>"));
				} else {
					hezhibtn13.setSelected(true);
					ball_hezhi_dintInt.addInt(15);
					hezhibtn13.setText(Html
							.fromHtml("<font color='#ffffff'><big>15</big></font><br> <font color='#ffffff'>奖金25</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn14 = (Button) findViewById(R.id.buy_kuai3_hezhi14);
		hezhibtn14.setSelected(false);
		// hezhibtn14.setText("16\n奖金40");
		hezhibtn14.setText(Html
				.fromHtml("<font color='#333333'><big>16</big></font><br> <font color='#777777'>奖金40</font>"));
		hezhibtn14.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn14.isSelected()) {
					hezhibtn14.setSelected(false);
					ball_hezhi_dintInt.remove(16);
					hezhibtn14.setText(Html
							.fromHtml("<font color='#333333'><big>16</big></font><br> <font color='#777777'>奖金40</font>"));
				} else {
					hezhibtn14.setSelected(true);
					ball_hezhi_dintInt.addInt(16);
					hezhibtn14.setText(Html
							.fromHtml("<font color='#ffffff'><big>16</big></font><br> <font color='#ffffff'>奖金40</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn15 = (Button) findViewById(R.id.buy_kuai3_hezhi15);
		hezhibtn15.setSelected(false);
		// hezhibtn15.setText("17\n奖金80");
		hezhibtn15.setText(Html
				.fromHtml("<font color='#333333'><big>17</big></font><br> <font color='#777777'>奖金80</font>"));
		hezhibtn15.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn15.isSelected()) {
					hezhibtn15.setSelected(false);
					ball_hezhi_dintInt.remove(17);
					hezhibtn15.setText(Html
							.fromHtml("<font color='#333333'><big>17</big></font><br> <font color='#777777'>奖金80</font>"));
				} else {
					hezhibtn15.setSelected(true);
					ball_hezhi_dintInt.addInt(17);
					hezhibtn15.setText(Html
							.fromHtml("<font color='#ffffff'><big>17</big></font><br> <font color='#ffffff'>奖金80</font>"));
				}
				getMoneyInfo();
			}
		});

		hezhibtn16 = (Button) findViewById(R.id.buy_kuai3_hezhi16);
		hezhibtn16.setSelected(false);
		// hezhibtn16.setText("18\n奖金240");
		hezhibtn16.setText(Html
				.fromHtml("<font color='#333333'><big>18</big></font><br> <font color='#777777'>奖金240</font>"));
		hezhibtn16.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (hezhibtn16.isSelected()) {
					hezhibtn16.setSelected(false);
					ball_hezhi_dintInt.remove(666);// 18 666
					hezhibtn16.setText(Html
							.fromHtml("<font color='#333333'><big>18</big></font><br> <font color='#777777'>奖金240</font>"));
				} else {
					hezhibtn16.setSelected(true);
					ball_hezhi_dintInt.addInt(666);// 18 666
					hezhibtn16.setText(Html
							.fromHtml("<font color='#ffffff'><big>18</big></font><br> <font color='#ffffff'>奖金240</font>"));
				}
				getMoneyInfo();
			}
		});

	}

	/**
	 * 三同号通选
	 */
	public void init3TongHaoTXBall() {
		ball_3ttx_dintInt = new DynArrayInt();

		btn_3ttongxuan_3ltongxuan = (Button) findViewById(R.id.btn_3ttongxuan_3ltongxuan);
		btn_3ttongxuan_3ltongxuan.setSelected(false);
		btn_3ttongxuan_3ltongxuan.setText("111,222,333,444,555,666");
		btn_3ttongxuan_3ltongxuan.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (btn_3ttongxuan_3ltongxuan.isSelected()) {
					btn_3ttongxuan_3ltongxuan.setSelected(false);
					ball_3ttx_dintInt.remove(1);

				} else {
					btn_3ttongxuan_3ltongxuan.setSelected(true);
					ball_3ttx_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});
	}

	/**
	 * 三连号通选
	 */
	public void init3LianHaoTXBall() {
		ball_3ltx_dintInt = new DynArrayInt();

		btn_3ttongxuan_3ltongxuan = (Button) findViewById(R.id.btn_3ttongxuan_3ltongxuan);
		btn_3ttongxuan_3ltongxuan.setSelected(false);
		btn_3ttongxuan_3ltongxuan.setText("123,234,345,456");
		btn_3ttongxuan_3ltongxuan.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (btn_3ttongxuan_3ltongxuan.isSelected()) {
					btn_3ttongxuan_3ltongxuan.setSelected(false);
					ball_3ltx_dintInt.remove(1);

				} else {
					btn_3ttongxuan_3ltongxuan.setSelected(true);
					ball_3ltx_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});
	}

	/**
	 * 三同号单选 二同号复选 三不同号 二不同号 公用
	 */
	public void init3TongHaoDXBall(int playtypeid) {
		ball_6btn_dintInt = new DynArrayInt();

		buy_kuai3_6btn_01 = (Button) findViewById(R.id.buy_kuai3_6btn_01);
		buy_kuai3_6btn_01.setSelected(false);
		if (playtypeid == 6604) {// 三同号单选
			buy_kuai3_6btn_01.setText("111");
		} else if (playtypeid == 6606) {// 二同号复选
			buy_kuai3_6btn_01.setText("11*");
		} else if (playtypeid == 6605 || playtypeid == 6608) {// //三不同号 二不同号
			buy_kuai3_6btn_01.setText("1");
		}

		buy_kuai3_6btn_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_6btn_01.isSelected()) {
					buy_kuai3_6btn_01.setSelected(false);
					ball_6btn_dintInt.remove(1);

				} else {
					buy_kuai3_6btn_01.setSelected(true);
					ball_6btn_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_6btn_02 = (Button) findViewById(R.id.buy_kuai3_6btn_02);
		buy_kuai3_6btn_02.setSelected(false);
		if (playtypeid == 6604) {// 三同号单选
			buy_kuai3_6btn_02.setText("222");
		} else if (playtypeid == 6606) {// 二同号复选
			buy_kuai3_6btn_02.setText("22*");
		} else if (playtypeid == 6605 || playtypeid == 6608) {// //三不同号 二不同号
			buy_kuai3_6btn_02.setText("2");
		}
		buy_kuai3_6btn_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_6btn_02.isSelected()) {
					buy_kuai3_6btn_02.setSelected(false);
					ball_6btn_dintInt.remove(2);

				} else {
					buy_kuai3_6btn_02.setSelected(true);
					ball_6btn_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_6btn_03 = (Button) findViewById(R.id.buy_kuai3_6btn_03);
		buy_kuai3_6btn_03.setSelected(false);
		if (playtypeid == 6604) {// 三同号单选
			buy_kuai3_6btn_03.setText("333");
		} else if (playtypeid == 6606) {// 二同号复选
			buy_kuai3_6btn_03.setText("33*");
		} else if (playtypeid == 6605 || playtypeid == 6608) {// //三不同号 二不同号
			buy_kuai3_6btn_03.setText("3");
		}
		buy_kuai3_6btn_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_6btn_03.isSelected()) {
					buy_kuai3_6btn_03.setSelected(false);
					ball_6btn_dintInt.remove(3);

				} else {
					buy_kuai3_6btn_03.setSelected(true);
					ball_6btn_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_6btn_04 = (Button) findViewById(R.id.buy_kuai3_6btn_04);
		buy_kuai3_6btn_04.setSelected(false);
		if (playtypeid == 6604) {// 三同号单选
			buy_kuai3_6btn_04.setText("444");
		} else if (playtypeid == 6606) {// 二同号复选
			buy_kuai3_6btn_04.setText("44*");
		} else if (playtypeid == 6605 || playtypeid == 6608) {// //三不同号 二不同号
			buy_kuai3_6btn_04.setText("4");
		}
		buy_kuai3_6btn_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_6btn_04.isSelected()) {
					buy_kuai3_6btn_04.setSelected(false);
					ball_6btn_dintInt.remove(4);

				} else {
					buy_kuai3_6btn_04.setSelected(true);
					ball_6btn_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_6btn_05 = (Button) findViewById(R.id.buy_kuai3_6btn_05);
		buy_kuai3_6btn_05.setSelected(false);
		if (playtypeid == 6604) {// 三同号单选
			buy_kuai3_6btn_05.setText("555");
		} else if (playtypeid == 6606) {// 二同号复选
			buy_kuai3_6btn_05.setText("55*");
		} else if (playtypeid == 6605 || playtypeid == 6608) {// //三不同号 二不同号
			buy_kuai3_6btn_05.setText("5");
		}
		buy_kuai3_6btn_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_6btn_05.isSelected()) {
					buy_kuai3_6btn_05.setSelected(false);
					ball_6btn_dintInt.remove(5);

				} else {
					buy_kuai3_6btn_05.setSelected(true);
					ball_6btn_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_6btn_06 = (Button) findViewById(R.id.buy_kuai3_6btn_06);
		buy_kuai3_6btn_06.setSelected(false);
		if (playtypeid == 6604) {// 三同号单选
			buy_kuai3_6btn_06.setText("666");
		} else if (playtypeid == 6606) {// 二同号复选
			buy_kuai3_6btn_06.setText("66*");
		} else if (playtypeid == 6605 || playtypeid == 6608) {// //三不同号 二不同号
			buy_kuai3_6btn_06.setText("6");
		}
		buy_kuai3_6btn_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_6btn_06.isSelected()) {
					buy_kuai3_6btn_06.setSelected(false);
					ball_6btn_dintInt.remove(6);

				} else {
					buy_kuai3_6btn_06.setSelected(true);
					ball_6btn_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});

	}

	/**
	 * 二同号单选 同号
	 */
	public void init2TongHaoDXBall1() {
		ball_2thdx1_dintInt = new DynArrayInt();

		buy_kuai3_t_01 = (Button) findViewById(R.id.buy_kuai3_t_01);
		buy_kuai3_t_01.setSelected(false);
		buy_kuai3_t_01.setText("11");
		buy_kuai3_t_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_t_01.isSelected()) {
					buy_kuai3_t_01.setSelected(false);
					ball_2thdx1_dintInt.remove(1);

				} else {
					// 11 和1只能选一个
					buy_kuai3_bt_01 = (Button) findViewById(R.id.buy_kuai3_bt_01);
					if (buy_kuai3_bt_01.isSelected()) {
						buy_kuai3_bt_01.setSelected(false);
						ball_2thdx2_dintInt.remove(1);
					}

					buy_kuai3_t_01.setSelected(true);
					ball_2thdx1_dintInt.addInt(1);

				}

				getMoneyInfo();
			}
		});

		buy_kuai3_t_02 = (Button) findViewById(R.id.buy_kuai3_t_02);
		buy_kuai3_t_02.setSelected(false);
		buy_kuai3_t_02.setText("22");
		buy_kuai3_t_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_t_02.isSelected()) {
					buy_kuai3_t_02.setSelected(false);
					ball_2thdx1_dintInt.remove(2);

				} else {
					buy_kuai3_bt_02 = (Button) findViewById(R.id.buy_kuai3_bt_02);
					if (buy_kuai3_bt_02.isSelected()) {
						buy_kuai3_bt_02.setSelected(false);
						ball_2thdx2_dintInt.remove(2);
					}
					buy_kuai3_t_02.setSelected(true);
					ball_2thdx1_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_t_03 = (Button) findViewById(R.id.buy_kuai3_t_03);
		buy_kuai3_t_03.setSelected(false);
		buy_kuai3_t_03.setText("33");
		buy_kuai3_t_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_t_03.isSelected()) {
					buy_kuai3_t_03.setSelected(false);
					ball_2thdx1_dintInt.remove(3);

				} else {
					buy_kuai3_bt_03 = (Button) findViewById(R.id.buy_kuai3_bt_03);
					if (buy_kuai3_bt_03.isSelected()) {
						buy_kuai3_bt_03.setSelected(false);
						ball_2thdx2_dintInt.remove(3);
					}
					buy_kuai3_t_03.setSelected(true);
					ball_2thdx1_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_t_04 = (Button) findViewById(R.id.buy_kuai3_t_04);
		buy_kuai3_t_04.setSelected(false);
		buy_kuai3_t_04.setText("44");
		buy_kuai3_t_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_t_04.isSelected()) {
					buy_kuai3_t_04.setSelected(false);
					ball_2thdx1_dintInt.remove(4);

				} else {
					buy_kuai3_bt_04 = (Button) findViewById(R.id.buy_kuai3_bt_04);
					if (buy_kuai3_bt_04.isSelected()) {
						buy_kuai3_bt_04.setSelected(false);
						ball_2thdx2_dintInt.remove(4);
					}
					buy_kuai3_t_04.setSelected(true);
					ball_2thdx1_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_t_05 = (Button) findViewById(R.id.buy_kuai3_t_05);
		buy_kuai3_t_05.setSelected(false);
		buy_kuai3_t_05.setText("55");
		buy_kuai3_t_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_t_05.isSelected()) {
					buy_kuai3_t_05.setSelected(false);
					ball_2thdx1_dintInt.remove(5);

				} else {
					buy_kuai3_bt_05 = (Button) findViewById(R.id.buy_kuai3_bt_05);
					if (buy_kuai3_bt_05.isSelected()) {
						buy_kuai3_bt_05.setSelected(false);
						ball_2thdx2_dintInt.remove(5);
					}
					buy_kuai3_t_05.setSelected(true);
					ball_2thdx1_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_t_06 = (Button) findViewById(R.id.buy_kuai3_t_06);
		buy_kuai3_t_06.setSelected(false);
		buy_kuai3_t_06.setText("66");
		buy_kuai3_t_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_t_06.isSelected()) {
					buy_kuai3_t_06.setSelected(false);
					ball_2thdx1_dintInt.remove(6);

				} else {
					buy_kuai3_bt_06 = (Button) findViewById(R.id.buy_kuai3_bt_06);
					if (buy_kuai3_bt_06.isSelected()) {
						buy_kuai3_bt_06.setSelected(false);
						ball_2thdx2_dintInt.remove(6);
					}
					buy_kuai3_t_06.setSelected(true);
					ball_2thdx1_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});
	}

	/**
	 * 二同号单选 不同号
	 */
	public void init2TongHaoDXBall2() {
		// 以下是不同号
		ball_2thdx2_dintInt = new DynArrayInt();
		buy_kuai3_bt_01 = (Button) findViewById(R.id.buy_kuai3_bt_01);
		buy_kuai3_bt_01.setSelected(false);
		buy_kuai3_bt_01.setText("1");
		buy_kuai3_bt_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_bt_01.isSelected()) {
					buy_kuai3_bt_01.setSelected(false);
					ball_2thdx2_dintInt.remove(1);

				} else {
					buy_kuai3_t_01 = (Button) findViewById(R.id.buy_kuai3_t_01);
					if (buy_kuai3_t_01.isSelected()) {
						buy_kuai3_t_01.setSelected(false);
						ball_2thdx1_dintInt.remove(1);
					}
					buy_kuai3_bt_01.setSelected(true);
					ball_2thdx2_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_bt_02 = (Button) findViewById(R.id.buy_kuai3_bt_02);
		buy_kuai3_bt_02.setSelected(false);
		buy_kuai3_bt_02.setText("2");
		buy_kuai3_bt_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_bt_02.isSelected()) {
					buy_kuai3_bt_02.setSelected(false);
					ball_2thdx2_dintInt.remove(2);

				} else {
					buy_kuai3_t_02 = (Button) findViewById(R.id.buy_kuai3_t_02);
					if (buy_kuai3_t_02.isSelected()) {
						buy_kuai3_t_02.setSelected(false);
						ball_2thdx1_dintInt.remove(2);
					}
					buy_kuai3_bt_02.setSelected(true);
					ball_2thdx2_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_bt_03 = (Button) findViewById(R.id.buy_kuai3_bt_03);
		buy_kuai3_bt_03.setSelected(false);
		buy_kuai3_bt_03.setText("3");
		buy_kuai3_bt_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_bt_03.isSelected()) {
					buy_kuai3_bt_03.setSelected(false);
					ball_2thdx2_dintInt.remove(3);

				} else {
					buy_kuai3_t_03 = (Button) findViewById(R.id.buy_kuai3_t_03);
					if (buy_kuai3_t_03.isSelected()) {
						buy_kuai3_t_03.setSelected(false);
						ball_2thdx1_dintInt.remove(3);
					}
					buy_kuai3_bt_03.setSelected(true);
					ball_2thdx2_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_bt_04 = (Button) findViewById(R.id.buy_kuai3_bt_04);
		buy_kuai3_bt_04.setSelected(false);
		buy_kuai3_bt_04.setText("4");
		buy_kuai3_bt_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_bt_04.isSelected()) {
					buy_kuai3_bt_04.setSelected(false);
					ball_2thdx2_dintInt.remove(4);

				} else {
					buy_kuai3_t_04 = (Button) findViewById(R.id.buy_kuai3_t_04);
					if (buy_kuai3_t_04.isSelected()) {
						buy_kuai3_t_04.setSelected(false);
						ball_2thdx1_dintInt.remove(4);
					}
					buy_kuai3_bt_04.setSelected(true);
					ball_2thdx2_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_bt_05 = (Button) findViewById(R.id.buy_kuai3_bt_05);
		buy_kuai3_bt_05.setSelected(false);
		buy_kuai3_bt_05.setText("5");
		buy_kuai3_bt_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_bt_05.isSelected()) {
					buy_kuai3_bt_05.setSelected(false);
					ball_2thdx2_dintInt.remove(5);

				} else {
					buy_kuai3_t_05 = (Button) findViewById(R.id.buy_kuai3_t_05);
					if (buy_kuai3_t_05.isSelected()) {
						buy_kuai3_t_05.setSelected(false);
						ball_2thdx1_dintInt.remove(5);
					}
					buy_kuai3_bt_05.setSelected(true);
					ball_2thdx2_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		buy_kuai3_bt_06 = (Button) findViewById(R.id.buy_kuai3_bt_06);
		buy_kuai3_bt_06.setSelected(false);
		buy_kuai3_bt_06.setText("6");
		buy_kuai3_bt_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_kuai3_bt_06.isSelected()) {
					buy_kuai3_bt_06.setSelected(false);
					ball_2thdx2_dintInt.remove(6);

				} else {
					buy_kuai3_t_06 = (Button) findViewById(R.id.buy_kuai3_t_06);
					if (buy_kuai3_t_06.isSelected()) {
						buy_kuai3_t_06.setSelected(false);
						ball_2thdx1_dintInt.remove(6);
					}
					buy_kuai3_bt_06.setSelected(true);
					ball_2thdx2_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});
	}

	/**
	 * 清空按钮事件清除数据
	 */
	public void btnClearSelectData() {
		if (playTypeId == 6601) {
			if (ball_hezhi_dintInt.getSize() != 0) {
				MyDialog.Builder dialog = new MyDialog.Builder(Kuai3Activity.this);
				dialog.setTitle("清空号码提示");
				dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
				dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						initBall();
						allMoney = 0;
						count = 0;
						moneyText.setText("0");
						countText.setText("0");
						tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
						buy_ssq_llfoot0.setVisibility(View.VISIBLE);
						buy_ssq_rlfoot1.setVisibility(View.GONE);
						dialog.cancel();
					}
				});
				dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create().show();
			} else {
				Toast.makeText(Kuai3Activity.this, R.string.number_did_not_choose, Toast.LENGTH_SHORT).show();
				initBall();
			}
		} else if (playTypeId == 6602) {
			if (ball_3ttx_dintInt.getSize() != 0) {
				AlertDialog.Builder dialog = new AlertDialog.Builder(Kuai3Activity.this);
				dialog.setTitle("清空号码提示");
				dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
				dialog.setIcon(R.drawable.yhzx_main_warn);
				dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						initBall();
						allMoney = 0;
						count = 0;
						moneyText.setText("0");
						countText.setText("0");
					}
				});
				dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create();
				dialog.show();
			} else {
				Toast.makeText(Kuai3Activity.this, R.string.number_did_not_choose, Toast.LENGTH_SHORT).show();
				initBall();
			}
		} else if (playTypeId == 6603) {
			if (ball_3ltx_dintInt.getSize() != 0) {
				AlertDialog.Builder dialog = new AlertDialog.Builder(Kuai3Activity.this);
				dialog.setTitle("清空号码提示");
				dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
				dialog.setIcon(R.drawable.yhzx_main_warn);
				dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						initBall();
						allMoney = 0;
						count = 0;
						moneyText.setText("0");
						countText.setText("0");
					}
				});
				dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create();
				dialog.show();
			} else {
				Toast.makeText(Kuai3Activity.this, R.string.number_did_not_choose, Toast.LENGTH_SHORT).show();
				initBall();
			}
		} else if (playTypeId == 6604 || playTypeId == 6605 || playTypeId == 6606 || playTypeId == 6608) {
			if (ball_6btn_dintInt.getSize() != 0) {
				AlertDialog.Builder dialog = new AlertDialog.Builder(Kuai3Activity.this);
				dialog.setTitle("清空号码提示");
				dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
				dialog.setIcon(R.drawable.yhzx_main_warn);
				dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						initBall();
						allMoney = 0;
						count = 0;
						moneyText.setText("0");
						countText.setText("0");
					}
				});
				dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create();
				dialog.show();
			} else {
				Toast.makeText(Kuai3Activity.this, R.string.number_did_not_choose, Toast.LENGTH_SHORT).show();
				initBall();
			}
		} else if (playTypeId == 6607) {
			if (ball_2thdx1_dintInt.getSize() != 0 && ball_2thdx2_dintInt.getSize() != 0) {
				AlertDialog.Builder dialog = new AlertDialog.Builder(Kuai3Activity.this);
				dialog.setTitle("清空号码提示");
				dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
				dialog.setIcon(R.drawable.yhzx_main_warn);
				dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						initBall();
						allMoney = 0;
						count = 0;
						moneyText.setText("0");
						countText.setText("0");
					}
				});
				dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create();
				dialog.show();
			} else {
				Toast.makeText(Kuai3Activity.this, R.string.number_did_not_choose, Toast.LENGTH_SHORT).show();
				initBall();
			}
		}
	}

	/**
	 * 初始化头部菜单玩法选择视图
	 */
	public void initSelectPlayTypeView() {
		initBall();
		allMoney = 0;
		count = 0;
		countText.setText(0 + "");
		moneyText.setText(0 + "");
		tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
		TextView top_title_tvplaytype = (TextView) findViewById(R.id.top_title_tvplaytype);
		top_title_tvplaytype.setText(strPlayType);

		switch (playTypeId) {
		case 6601:// 和值
			buy_kuai3_ll_hezhi.setVisibility(View.VISIBLE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.GONE);
			buy_kuai3_6btn.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.GONE);
			break;
		case 6602:// 三同号通选
			buy_kuai3_ll_hezhi.setVisibility(View.GONE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.VISIBLE);
			buy_kuai3_6btn.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.GONE);
			break;
		case 6603:// 三连号通选
			buy_kuai3_ll_hezhi.setVisibility(View.GONE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.VISIBLE);
			buy_kuai3_6btn.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.GONE);

			break;
		case 6604:// 三同号单选
			buy_kuai3_ll_hezhi.setVisibility(View.GONE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.GONE);
			buy_kuai3_6btn.setVisibility(View.VISIBLE);
			buy_kuai3_6btn_tvnote.setText(Html.fromHtml("至少选<font color='#fe5052'>"+1+"</font>个号码"));
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.GONE);

			break;
		case 6605:// 三不同号
			buy_kuai3_ll_hezhi.setVisibility(View.GONE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.GONE);
			buy_kuai3_6btn.setVisibility(View.VISIBLE);
			buy_kuai3_6btn_tvnote.setText(Html.fromHtml("至少选<font color='#fe5052'>"+3+"</font>个号码"));
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.GONE);

			break;
		case 6606:// 二同号复选
			buy_kuai3_ll_hezhi.setVisibility(View.GONE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.GONE);
			buy_kuai3_6btn.setVisibility(View.VISIBLE);
			buy_kuai3_6btn_tvnote.setText(Html.fromHtml("至少选<font color='#fe5052'>"+1+"</font>个号码"));
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.GONE);

			break;
		case 6607:// 二同号单选
			buy_kuai3_ll_hezhi.setVisibility(View.GONE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.GONE);
			buy_kuai3_6btn.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.VISIBLE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.VISIBLE);
			break;
		case 6608:
			buy_kuai3_ll_hezhi.setVisibility(View.GONE);
			buy_kuai3ll_3ttongxuan_3ltongxuan.setVisibility(View.GONE);
			buy_kuai3_6btn.setVisibility(View.VISIBLE);
			buy_kuai3_6btn_tvnote.setText(Html.fromHtml("至少选<font color='#fe5052'>"+2+"</font>个号码"));
			buy_kuai3_2tonghao_danxuan1.setVisibility(View.GONE);
			buy_kuai3_2tonghao_danxuan2.setVisibility(View.GONE);

			break;
		}

	}

	/**
	 * 菜单玩法按钮事件
	 * 
	 * @param btnId
	 */
	private void setBtnOnClick(final int btnId) {
		Button btn = (Button) menutypeview.findViewById(btnId);
		btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				menu_popupWindow.dismiss();
				setOrderField(btnId);
				if (ApplicationData.getInstance().getList_11x5dto().size() == 0
						&& ApplicationData.getInstance().getAll_11x5money() == 0
						&& ApplicationData.getInstance().getPlay_11x5Id() == 0) {
					initSelectPlayTypeView();
				} else {
					MyDialog.Builder dialog = new MyDialog.Builder(Kuai3Activity.this);
					dialog.setTitle("提示");
					dialog.setMessage("切换玩法将使之前所选号码清空，确认切换吗？");
					dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							ApplicationData.getInstance().initList();
							initSelectPlayTypeView();
							dialog.cancel();
						}
					});
					dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.cancel();
						}
					});
					dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
						@Override
						public void onCancel(DialogInterface dialog) {

							int app_playId = ApplicationData.getInstance().getPlay_11x5Id();
							// System.out.println("app_playId:" + app_playId +
							// "  playTypeId:" + playTypeId);
							if (app_playId == 6601) {
								playTypeId = 6601;
								strPlayType = "和值";
							} else if (app_playId == 6602) {
								playTypeId = 6602;
								strPlayType = "三同号通选";
							} else if (app_playId == 6603) {
								playTypeId = 6603;
								strPlayType = "三连号通选";
							} else if (app_playId == 6604) {
								playTypeId = 6604;
								strPlayType = "三同号单选";
							} else if (app_playId == 6605) {
								playTypeId = 6605;
								strPlayType = "三不同号";
							} else if (app_playId == 6606) {
								playTypeId = 6606;
								strPlayType = "二同号复选";
							} else if (app_playId == 6607) {
								playTypeId = 6607;
								strPlayType = "二同号单选";
							} else if (app_playId == 6608) {
								playTypeId = 6608;
								strPlayType = "二不同号";
							}

							// initSelectPlayTypeView();
							// dialog.cancel();
						}
					}).create().show();

				}
			}
		});
	}

	/**
	 * 获取玩法及改变按钮背景
	 * 
	 * @param btnId
	 */
	public void setOrderField(int btnId) {
		// 恢复默认
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button01)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button02)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button03)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button04)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button05)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button06)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button07)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button08)).setSelected(false);
		// ((Button)
		// findViewById(R.id.hemai_main_btnJD)).setTextColor(context.getResources().getColor(R.color.black));
		switch (btnId) {
		case R.id.buy_newkuai3_topmenulink_Button01:
			playTypeId = 6601;
			strPlayType = "和值";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button01)).setSelected(true);
			// ((Button)
			// findViewById(R.id.hemai_main_btnJD)).setTextColor(context.getResources().getColor(R.color.white));
			break;
		case R.id.buy_newkuai3_topmenulink_Button02:
			playTypeId = 6602;
			strPlayType = "三同号通选";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button02)).setSelected(true);
			break;
		case R.id.buy_newkuai3_topmenulink_Button03:
			playTypeId = 6603;
			strPlayType = "三连号通选";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button03)).setSelected(true);
			break;
		case R.id.buy_newkuai3_topmenulink_Button04:
			playTypeId = 6604;
			strPlayType = "三同号单选";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button04)).setSelected(true);
			break;
		case R.id.buy_newkuai3_topmenulink_Button05:
			playTypeId = 6605;
			strPlayType = "三不同号";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button05)).setSelected(true);
			break;
		case R.id.buy_newkuai3_topmenulink_Button06:
			playTypeId = 6606;
			strPlayType = "二同号复选";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button06)).setSelected(true);
			break;
		case R.id.buy_newkuai3_topmenulink_Button07:
			playTypeId = 6607;
			strPlayType = "二同号单选";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button07)).setSelected(true);
			break;
		case R.id.buy_newkuai3_topmenulink_Button08:
			playTypeId = 6608;
			strPlayType = "二不同号";
			((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button08)).setSelected(true);
			break;
		}
	}

	// TitleBar标题栏
	public void TitleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});

		TextView tvinfo = (TextView) findViewById(R.id.top_title_info);
		tvinfo.setText(R.string.buy_newkuai3);

		// final RelativeLayout top_title_rlplaytype = (RelativeLayout)
		// findViewById(R.id.top_title_rlplaytype);
		final LinearLayout buy_jclq_center_rl2 = (LinearLayout) findViewById(R.id.buy_jclq_center_rl2);
		buy_jclq_center_rl2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(Kuai3Activity.this);
				// View menutypeview =
				// inflater.inflate(R.layout.buy_new11x5_topmenulink, null);
				menutypeview = inflater.inflate(R.layout.buy_newkuai3_topmenulink, null);
				menu_popupWindow = new PopupWindow(menutypeview, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
				menu_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				
				menu_popupWindow.setFocusable(true);
				menu_popupWindow.setTouchable(true);
				menu_popupWindow.setOutsideTouchable(false);
				
				menu_popupWindow.showAtLocation(menutypeview, Gravity.CENTER | Gravity.TOP, 0, 0);
				menu_popupWindow.showAsDropDown(buy_jclq_center_rl2);
				menutypeview.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						// TODO Auto-generated method stub
						menu_popupWindow.dismiss();
					}
				});
				// 进度战绩总额按钮事件
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button01);
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button02);
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button03);
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button04);
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button05);
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button06);
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button07);
				setBtnOnClick(R.id.buy_newkuai3_topmenulink_Button08);
				// Log.d("elv", "点击menu_popupWindow");
				// select first button
				if (playTypeId == 6601) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button01)).setSelected(true);
				} else if (playTypeId == 6602) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button02)).setSelected(true);
				} else if (playTypeId == 6603) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button03)).setSelected(true);
				} else if (playTypeId == 6604) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button04)).setSelected(true);
				} else if (playTypeId == 6605) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button05)).setSelected(true);
				} else if (playTypeId == 6606) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button06)).setSelected(true);
				} else if (playTypeId == 6607) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button07)).setSelected(true);
				} else if (playTypeId == 6608) {
					((Button) menutypeview.findViewById(R.id.buy_newkuai3_topmenulink_Button08)).setSelected(true);
				}
			}
		});

		final Button refres = (Button) findViewById(R.id.top_title_refres);
		refres.setBackgroundDrawable(null);
		refres.setText("帮助");
//		refres.getBackground().setAlpha(255);
		// refres.setBackgroundResource(R.color.common_menu);
		refres.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(Kuai3Activity.this);
				View menuview = inflater.inflate(R.layout.public_menulink, null);
				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setOutsideTouchable(true);
				m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 0, 0);
				m_popupWindow.showAsDropDown(refres);

				menuview.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
					}
				});

				Button public_menulink_Button01 = (Button) menuview.findViewById(R.id.public_menulink_Button01);
				public_menulink_Button01.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							Intent intent0 = new Intent();
							intent0.putExtra("lotID", LOT_ID_KUAI3);
							intent0.setClass(Kuai3Activity.this, BetRecordActivity.class);
							startActivity(intent0);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_ELV);
						}
					}
				});

				Button public_menulink_Button02 = (Button) menuview.findViewById(R.id.public_menulink_Button02);
				public_menulink_Button02.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							intent = new Intent(getApplicationContext(), ZhRecordActivity.class);
							startActivity(intent);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_ELV);
						}
					}
				});
				Button public_menulink_Button03 = (Button) menuview.findViewById(R.id.public_menulink_Button03);
				public_menulink_Button03.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						intent = new Intent(getApplicationContext(), KjinfoListByType.class);
						intent.putExtra("LottID", LOT_ID_KUAI3 + "");
						intent.putExtra("LottName", getString(R.string.kjinfo_number_kuai3_info));
						startActivity(intent);
					}
				});
				Button public_menulink_Button04 = (Button) menuview.findViewById(R.id.public_menulink_Button04);
				public_menulink_Button04.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						// Intent intent = new Intent(getApplicationContext(),
						// HelpActivity.class);
						// startActivity(intent);
						Intent intent = new Intent(getApplicationContext(), CaiPiaoHelp.class);
						intent.putExtra("cp_title", "快三");
						intent.putExtra("cp_url", "k3.html");
						startActivity(intent);
					}
				});
			}
		});
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		// m_popupWindow.dismiss();
		// return super.onTouchEvent(event);
		if (m_popupWindow != null) {
			m_popupWindow.dismiss();
		}
		return super.onTouchEvent(event);
	}

	public boolean checkUserLogin() {
		// app_11x5dto = (ApplicationBall) getApplication();
		if (!ApplicationData.getInstance().getLoginName().equals("")
				&& !ApplicationData.getInstance().getLoginPwd().equals("")
				|| !ApplicationData.getInstance().getUserID().equals("")) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// app_11x5dto = (ApplicationBall) getApplication();
			if(ifbacklist) {
				Intent intent = new Intent();
				intent.putExtra("list_elvdto", ApplicationData.getInstance().getList_11x5dto());
				intent.putExtra("PlayTypeID", playTypeId);
				intent.putExtra("PlayType", strPlayType);
				intent.putExtra("AllMoney", ApplicationData.getInstance().getAll_11x5money());
				intent.putExtra("LotID", lotID);
				intent.putExtra("Count", count);
				intent.putExtra("IssueID", issueID);
				intent.putExtra("IssueName", issueName);
				prizeIntellChase = getIntent().getIntExtra("prizeIntellChase", 0);
				//Log.d("van",prizeIntellChase +"--------" );
				intent.putExtra("prizeIntellChase",prizeIntellChase);
				intent.setClass(Kuai3Activity.this, Kuai3ListActivity.class);
				startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
			} else {
				if(ifPush){
					Intent intent = new Intent(this, JddMainActivity.class);
					startActivity(intent);
				}
				ApplicationData.getInstance().initList();
			}
			// 停止监听
			sensor.stop();
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	};

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (requestCode == REQ_CODE_BUYMAIN && resultCode == RESULT_OK  ) {
			
			onKeyDown(KeyEvent.KEYCODE_BACK, null);
		}
		if(resultCode == RESULT_OK) {
		if(requestCode == REQ_CODE_BUY_LOGIN ) {
			goXhlbSubmit();
		}
		}
	};

	private void goXhlbSubmit() {
		// TODO Auto-generated method stub

		// TODO Auto-generated method stub
		if (checkUserLogin()) {
			if (issueName == null || issueName.equals("")) {
				Toast.makeText(Kuai3Activity.this, R.string.is_retrieving_period_time, Toast.LENGTH_SHORT)
						.show();
				return;
			}
			if (!(allMoney == 0 || count == 0)) {
				BallDTO elvdto = new BallDTO();
				// 获得自定义的应用程序BallDTO
				// app_11x5dto = (ApplicationBall) getApplication();
				String ball = "";
				if (playTypeId == 6601) {
					ball = ball_hezhi_dintInt.getAllIntToStringForSingleKuai3(ball_hezhi_dintInt.getAllInt());
				} else if (playTypeId == 6602) {
					ball = ball_3ttx_dintInt.getAllIntToStringForSingle(ball_3ttx_dintInt.getAllInt());
					if (ball.equals("1,")) {
						ball = "三同号通选,";
					}
				} else if (playTypeId == 6603) {
					ball = ball_3ltx_dintInt.getAllIntToStringForSingle(ball_3ltx_dintInt.getAllInt());
					if (ball.equals("1,")) {
						ball = "三连号通选,";
					}
				} else if (playTypeId == 6604) {// 三同号单选
					ball = ball_6btn_dintInt.getAllIntToStringForSingle(ball_6btn_dintInt.getAllInt());
					ball = ball.replace("1", "111").replace("2", "222").replace("3", "333").replace("4", "444")
							.replace("5", "555").replace("6", "666");
				} else if (playTypeId == 6606) {// 二同号复选
					ball = ball_6btn_dintInt.getAllIntToStringForSingle(ball_6btn_dintInt.getAllInt());
					ball = ball.replace("1", "11*").replace("2", "22*").replace("3", "33*").replace("4", "44*")
							.replace("5", "55*").replace("6", "66*");
				} else if (playTypeId == 6605 || playTypeId == 6608) {
					ball = ball_6btn_dintInt.getAllIntToStringForSingle(ball_6btn_dintInt.getAllInt());

				} else if (playTypeId == 6607) {
					// ball =
					// ball_2thdx1_dintInt.getAllIntToStringForSingle(ball_2thdx1_dintInt.getAllInt())+" "+ball_2thdx2_dintInt.getAllIntToStringForSingle(ball_2thdx2_dintInt.getAllInt());
					String tonghao = ball_2thdx1_dintInt.getAllIntToStringForSingle(ball_2thdx1_dintInt
							.getAllInt());
					// tonghao=tonghao.replace(",", " ").trim();
					tonghao = tonghao.replace("1", "11").replace("2", "22").replace("3", "33")
							.replace("4", "44").replace("5", "55").replace("6", "66");
					ball = tonghao + "#"
							+ ball_2thdx2_dintInt.getAllIntToStringForSingle(ball_2thdx2_dintInt.getAllInt());
				}

				// String ball =
				// ball_hezhi_dintInt.getAllIntToStringForSingle(ball_hezhi_dintInt.getAllInt());
				Log.i("kuai3", "确定 跳转按钮  ball= " + ball);
				// ball = ball.substring(0, ball.length() - 1);
				sendIntent(elvdto, ball);
			} else {
				// if
				// (ApplicationData.getInstance().getList_11x5dto().size()
				// == 0) {
				Toast.makeText(Kuai3Activity.this, R.string.select_a_valid_bets_number, Toast.LENGTH_SHORT)
						.show();
				// } else {
				// Intent intent = new Intent();
				// intent.putExtra("list_elvdto",
				// ApplicationData.getInstance().getList_11x5dto());
				// intent.putExtra("PlayTypeID", playTypeId);
				// intent.putExtra("PlayType", strPlayType);
				// intent.putExtra("AllMoney",
				// ApplicationData.getInstance().getAll_11x5money());
				// intent.putExtra("LotID", lotID);
				// intent.putExtra("Count", count);
				// intent.putExtra("IssueID", issueID);
				// intent.putExtra("IssueName", issueName);
				// intent.setClass(Kuai3Activity.this,
				// Kuai3ListActivity.class);
				// startActivityForResult(intent, REQ_CODE_BUYMAIN);//
				// (intent);
				// }
			}
		} else {
			Intent intent = new Intent();
			intent.setClass(Kuai3Activity.this, LoginActivity.class);
			startActivityForResult(intent, REQ_CODE_BUY_LOGIN);
		}
	
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	};

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		handler.removeCallbacks(runnable);
		super.onDestroy();
	}
}